﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WisdriContacts.Resources;
using WisdriContacts.ViewModels;
using WisdriContacts.Model;

namespace WisdriContacts
{
    public partial class DepartmentPage : PhoneApplicationPage
    {
        // 构造函数
        public DepartmentPage()
        {
            InitializeComponent();

            // 将 LongListSelector 控件的数据上下文设置为示例数据
            DataContext = App.ViewModel;

            // 用于本地化 ApplicationBar 的示例代码
            //BuildLocalizedApplicationBar();
        }


        // 处理在 LongListSelector 中更改的选定内容
        private void MainLongListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // 如果所选项为空(没有选定内容)，则不执行任何操作
            if (MainLongListSelector.SelectedItem == null)
                return;

            App.ViewModel.SubTitle = MainLongListSelector.SelectedItem as string;

            // 导航到新页面
            NavigationService.Navigate(
                new Uri("/ContactListPage.xaml?selectedItem=" + (MainLongListSelector.SelectedItem as string),
                    UriKind.Relative));

            // 将所选项重置为 null (没有选定内容)
            MainLongListSelector.SelectedItem = null;
        }

        // 用于生成本地化 ApplicationBar 的示例代码
        private void BuildLocalizedApplicationBar()
        {
            // 将页面的 ApplicationBar 设置为 ApplicationBar 的新实例。
            ApplicationBar = new ApplicationBar();

            // 创建新按钮并将文本值设置为 AppResources 中的本地化字符串。
            ApplicationBarIconButton appBarButtonDepartment =
                new ApplicationBarIconButton(new Uri("/Assets/Icons/folder.png", UriKind.Relative));
            appBarButtonDepartment.Text = AppResources.AppBarButtonDepartment;
            ApplicationBar.Buttons.Add(appBarButtonDepartment);

            ApplicationBarIconButton appBarButtonSearch =
                new ApplicationBarIconButton(new Uri("/Assets/Icons/feature.search.png", UriKind.Relative));
            appBarButtonSearch.Text = AppResources.AppBarButtonSearch;
            ApplicationBar.Buttons.Add(appBarButtonSearch);

            ApplicationBarIconButton appBarButtonExit =
                new ApplicationBarIconButton(new Uri("/Assets/Icons/close.png", UriKind.Relative));
            appBarButtonExit.Text = AppResources.AppBarButtonExit;
            ApplicationBar.Buttons.Add(appBarButtonExit);

            // 使用 AppResources 中的本地化字符串创建新菜单项。
            //ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
            //ApplicationBar.MenuItems.Add(appBarMenuItem);
        }
    }
}